//
//  KDLibraryLocationWindowController.m
//  Source List
//
//  Created by Keith Duncan on 15/05/2008.
//  Copyright 2008 Disney Store. All rights reserved.
//

#import "AFLocateLibraryWindowController.h"

@interface AFLocateLibraryWindowController ()
@property (readwrite, assign) NSTextField *libraryPathField;
@end

@implementation AFLocateLibraryWindowController

@synthesize library;
@synthesize expectedLocation;
@synthesize libraryPathField;

- (id)initWithNibName:(NSString *)name bundle:(NSBundle *)bundle {
	return [self initWithWindowNibName:name owner:self];
}

- (void)windowDidLoad; {
	[super windowDidLoad];
	
	[[self window] setContentBorderThickness:(25.0 + 16.0) forEdge:NSMinYEdge];
}

- (void)dealloc {
	[expectedLocation release];
	
	[super dealloc];
}

- (IBAction)browse:(id)sender {
	NSOpenPanel *open = [NSOpenPanel openPanel];
	
	[open setCanChooseDirectories:NO];
	[open setCanCreateDirectories:NO];
	[open setAllowsMultipleSelection:NO];
	
	if ([open runModalForDirectory:[expectedLocation stringByDeletingLastPathComponent] file:nil types:[NSArray arrayWithObject:@"xml"]] == NSOKButton) {
		[libraryPathField setStringValue:[open filename]];
		[NSApp stopModal];
	}
}

- (NSString *)requestLibraryLocation {
	[self showWindow:nil];
	[[self window] center];
	
	[NSApp runModalForWindow:[self window]];
	
	[NSApp endSheet:[self window]];
	[self close];
	
	return [[[libraryPathField stringValue] copy] autorelease];
}

- (IBAction)endRequest:(id)sender {
	[NSApp stopModal];
}

@end
